﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Seek : System.Web.UI.Page
{
    PagedDataSource pds = new PagedDataSource();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    private void Bind()
    {
        if (Session["Name"] == null)
        {
            Response.Write("<script>alert('你还没登录，请先登录账号！');window.location.href='Logon.aspx';</script>");
        }
        else
        {
            string date = DateTime.Now.ToString("yyyy - MM - dd");
            string Doc = Session["Name"].ToString();
            string sql = string.Format("select * from Register INNER JOIN Patient ON Register.PatIDCard = Patient.IDCard where DocID='{0}' and VisStatus='未就诊' and Register.DauyDate>='{1}'", Doc,date);
            DataSet set = DBHelper.GetDataSet(sql);
            pds.DataSource = set.Tables[0].DefaultView;
            pds.AllowPaging = true;
            pds.PageSize = 12;
            pds.CurrentPageIndex = Convert.ToInt32(ViewState["Page"]);
            this.lblTotle.Text = "共有" + pds.PageCount.ToString() + "页";
            this.lblCurrent.Text = "当前第" + (pds.CurrentPageIndex + 1).ToString() + "页";
            ViewState["PageCount"] = pds.PageCount;
            Enabled();
            DataList1.DataSource = pds;
            DataBind();
        }
    }

    private void Enabled()
    {
        this.Button1.Enabled = true;
        this.Button2.Enabled = true;
        if (pds.IsFirstPage)
        {
            this.Button1.Enabled = false;
        }
        if (pds.IsLastPage)
        {
            this.Button2.Enabled = false;
        }
    }

    //首页
    protected void Button3_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = 0;
        Bind();
    }

    //上一页
    protected void Button1_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) - 1;
        Bind();
    }

    //下一页
    protected void Button2_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["Page"]) + 1;
        Bind();
    }

    //尾页
    protected void Button4_Click(object sender, EventArgs e)
    {
        ViewState["Page"] = Convert.ToInt32(ViewState["PageCount"]) - 1;
        Bind();
    }
}